package org.dandelion.goalTest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

import org.dandelion.R;
import org.dandelion.goalTest.util.DBHelper;


public class GoalListActivity extends AppCompatActivity {
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student_goals);

//        SQLiteStudioService.instance().start(this);


        listView = findViewById(R.id.listView);

        Intent intent = getIntent();
        int stu_id = intent.getIntExtra("stu_id", 0);
        if (stu_id == 0) {
            Toast.makeText(this, "no date get", Toast.LENGTH_SHORT).show();
            finish();
        }
        DBHelper dbHelper = new DBHelper(this);
        Cursor cursor = dbHelper.selectStudent_Course(stu_id);
        cursor.moveToFirst();
        SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(
                this,
                R.layout.goal_list_item,
                cursor,
                new String[]{"course_id", "name", "goal", "type", "credit"},
                new int[]{R.id.course_id, R.id.name, R.id.goal, R.id.type, R.id.credit},
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        listView.setAdapter(simpleCursorAdapter);
    }
}